<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Notepad</title>

    <!-- bootstrap -->
    <link rel="stylesheet" href="./assets/css/bootstrap.min.css" />

    <!-- muiUI -->
    <link rel="stylesheet" href="./assets/plugins/mui/css/mui.min.css">

    <!-- animate.css -->
    <link rel="stylesheet" href="./assets/css/animate.min.css" />

    <!-- 重置样式 -->
    <link rel="stylesheet" href="./assets/css/reset.css" />

    <!-- 公共样式 -->
    <link rel="stylesheet" href="./assets/css/common.css" />

    <!-- 页面独立的 -->
    <link rel="stylesheet" href="./assets/css/UserLogin.css" />
</head>

<body>
    <!-- 用户信息 -->
    <div class="user">
        <div class="avatar wow fadeInUp">
            <img src="./assets/images/avatar.png" />
        </div>

        <div class="notice wow fadeInUp" data-wow-delay="100ms">账号登录</div>
    </div>

    <form class="login wow fadeInUp" data-wow-delay="200ms">
        <div class="form-group">
            <label for="mobile">手机号</label>
            <input type="mobile" class="form-control" id="mobile" placeholder="请输入手机号" required />
        </div>

        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" class="form-control" id="password" placeholder="请输入密码" required />
        </div>

        <div class="action">
            <button class="btn">登录</button>
        </div>
    </form>
</body>

</html>
<!-- jquery  -->
<script src="./assets/js/jquery.min.js"></script>

<!-- bootstrap -->
<script src="./assets/js/bootstrap.min.js"></script>

<!-- wow.js -->
<script src="./assets/js/wow.min.js"></script>

<!-- muiUI -->
<script src="./assets/plugins/mui/js/mui.min.js"></script>

<!-- axios -->
<script src="./assets/plugins/axios/axios.min.js"></script>

<!-- 自己封装的接口文件 -->
<script src="./assets/plugins/axios/request.js"></script>

<!-- 引入cookie封装文件 -->
<script src="./assets/plugins/cookie.js"></script>

<!-- 引入登录判断的文件 -->
<script src="./assets/plugins/login.js"></script>
<script>
     //实例化wow.js
     new WOW().init()

//给表单绑定点击事件
$(".login").submit(async function(e){
    //提交功能阻止
    e.preventDefault();

    //获取邮箱和密码的内容
    var mobile = $.trim($('#mobile').val())
    var password = $.trim($('#password').val())
    
    //正则表达式
    var reg = /^1[3-9]\d{9}/
    if(!reg.test(mobile))
    {
        mui.alert('手机号码格式不正确')
        return false
    }

    //验证密码
    var reg = /^[a-zA-Z0-9]{4,16}$/;

    if(!reg.test(password))
    {
        mui.alert('密码格式不正确')
        return false
    }
    
    //组装数据
    var data = {
        mobile,
        password
    }

    //发送请求
    var result = await POST({
        url: '/business/login',
        params: data
    })

    //判断是否登录成功
    if(result.code == 0)
    {
        mui.alert(result.msg)
        return false
    }else
    {
        //要将用户信息保存起来(本地存储，cookie)
        cookie.set('business', JSON.stringify(result.data))

        location.href = 'UserIndex.html'
    }
})

</script>